package com.wise.service.portal.content.homedecorate;

import com.wise.entities.content.Decorate;
import com.wise.entities.content.DecorateModule;
import com.wise.entities.content.DecorateType;
import com.wise.framework.dao.SqlSelect;
import com.wise.framework.daomodel.DaoList;
import com.wise.summer.v1.portal.content.homedecorate.GetHomeDecorate;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.summerframework.model.SummerService;
import org.summerframework.model.SummerServiceBean;

import java.util.List;


@Service
@SummerService
public class GetHomeDecorateService implements SummerServiceBean<GetHomeDecorate> {

	/**
	 * 根据type,module,lang查询分页信息
	 *
	 * @param model
	 */
	@Override
	public void sum(GetHomeDecorate model) {
		/* 执行查询，看是否为空，为空则新增，不为空则update */
		SqlSelect sql = SqlSelect.selec("*");
		/* type和module由后台负责处理，前台不传参 */
		sql.fromClassName(Decorate.class);
		sql.eq("type", DecorateType.PC.value());
		sql.eq("module", DecorateModule.HOME.value());
		sql.eqLang(Decorate._lang);
		/* 只执行查询数据，不分页*/
		List<Decorate> resourceList = DaoList.s(Decorate.class, sql, 0, 1);

		if (!CollectionUtils.isEmpty(resourceList)) {
			Decorate decorate = resourceList.get(0);
			// decorate.setContent("");
			model.setSummerResult(decorate);
		}
	}
}
